package com.lbs.jiepiaisi.parser;
import com.lbs.jiepiaisi.bean.EqnoLoginBean;

import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * 时间：2017/8/11 11:24
 * 作用：拍照登录解析类
 */

public class LoginPhotoParser {
    //解析方法
    public static EqnoLoginBean parser(String jsonString){

        EqnoLoginBean eqnoLoginBean =new EqnoLoginBean();
        try{
            JSONObject jsonObject=new JSONObject(jsonString);
            int code=jsonObject.getInt("status");
            //登录成功
            if(code==0){
//                eqnoLoginBean.setStatus(code);
                JSONObject resultJson = jsonObject.getJSONObject("result");
                EqnoLoginBean.Result result = new EqnoLoginBean.Result();
                result.setEqId(resultJson.getString("eqId"));
                result.setEqDeptName(resultJson.getString("eqDeptName"));
                result.setEqNo(resultJson.getString("eqNo"));
                result.setEqModel(resultJson.getString("eqModel"));
                result.setOwnerName(resultJson.getString("ownerName"));
                result.setSim(resultJson.getString("sim"));
                result.setEqPosition(resultJson.getString("eqPosition"));
                result.setStatus(resultJson.getString("status"));
                EqnoLoginBean.Result.Point point = null;
                if(resultJson.has("point")){
                    try {
                        JSONObject pointObject = resultJson.getJSONObject("point");
                        point = new EqnoLoginBean.Result.Point();
                        if(pointObject.has("dir")){
                            point.setDir(pointObject.getInt("dir"));
                        }
                        if(pointObject.has("lat")){
                            point.setLat(pointObject.getDouble("lat"));
                        }
                        if(pointObject.has("lng")){
                            point.setLng(pointObject.getDouble("lng"));
                        }
                        if(pointObject.has("positionTime")){
                            point.setPositionTime(pointObject.getString("positionTime"));
                        }

                    }catch (JSONException e){
                        e.printStackTrace();
                        point = null;
                    }

                }
                result.setPoint(point);

                eqnoLoginBean.setResult(result);
            }else if(code==1){//登录失败，图片已经存在
//                eqnoLoginBean.setStatus(code);
            }else if(code==2){//登录失败，设备不存在
//                eqnoLoginBean.setStatus(code);
            }else if(code==3){//设备存在，信息不全
//                eqnoLoginBean.setStatus(code);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return eqnoLoginBean;
    }

}
